//
//  RHGroupUserCell.m
//  RuiHeApp
//
//  Created by Yan Chen on 2024/11/14.
//

#import "RHGroupAddUserCell.h"
@interface RHGroupAddUserCell()
@property(nonatomic,strong)UIImageView *userIcon;
@property(nonatomic,strong)QMUILabel *userNameLab;
@property(nonatomic,strong)QMUILabel *emailLab;
@property(nonatomic,strong)UIImageView *arrowImg;
@end
@implementation RHGroupAddUserCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self setupUI];
    }
    return self;
}
-(void)setUsermodel:(RHUserModel *)usermodel
{
    _usermodel = usermodel;
    self.userNameLab.text = usermodel.remarkName?usermodel.remarkName:usermodel.userName;
    self.emailLab.text = usermodel.email;
   
    [self.userIcon sd_setImageWithURL:[NSURL URLWithString:usermodel.avatar] placeholderImage:[UIImage imageNamed:@"kwt_avatar_default"]];
    self.arrowImg.image = [UIImage imageNamed:usermodel.isSelected?@"ugrade_select":@"ugrade_cancel"];
}
- (void)setupUI{
    
    [self setBackgroundColor:UIColor.clearColor];
    [self.contentView setBackgroundColor:UIColor.clearColor];
    
    UIView *containView = [[UIView alloc]init];
    [self.contentView addSubview:containView];
    containView.backgroundColor = [UIColor whiteColor];
    containView.layer.cornerRadius = 8;
    containView.layer.masksToBounds = YES;
    
    _userIcon = [[UIImageView alloc]init];
    [_userIcon setImage:[UIImage imageNamed:@"kwt_avatar_default"]];
    _userIcon.contentMode = UIViewContentModeScaleAspectFill;
    _userIcon.layer.cornerRadius = kScaleW(25);
    _userIcon.layer.masksToBounds = YES;
    [containView addSubview:_userIcon];
    
    
    _userNameLab = [[QMUILabel alloc]init];
    [containView addSubview:_userNameLab];
    _userNameLab.font = [UIFont boldSystemFontOfSize:15];
    _userNameLab.text = @"User";
    _userNameLab.textAlignment = NSTextAlignmentLeft;
    _userNameLab.textColor = [UIColor colorWithHexString:@"3F4443"];

    
    _emailLab = [[QMUILabel alloc]init];
    [containView addSubview:_emailLab];
    _emailLab.font = [UIFont boldSystemFontOfSize:13];
    _emailLab.text = @"5";
    _emailLab.textAlignment = NSTextAlignmentLeft;
    _emailLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.6];
   
    
    kWeakSelf;
    _arrowImg = [[UIImageView alloc]init];
    [containView addSubview:_arrowImg];
    [_arrowImg setImage:[UIImage imageNamed:@"ugrade_cancel"]];
  
    [containView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.insets(UIEdgeInsetsMake(10, 10, 10, 10));
    }];
    
    [_userIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.offset(10);
            make.width.height.offset(kScaleW(50));
            make.bottom.mas_offset(-10);
    }];
    
    [_userNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.userIcon.mas_right).offset(5);
            make.right.equalTo(weakSelf.arrowImg.mas_left).offset(-3);
            make.top.equalTo(weakSelf.userIcon).offset(5);
    }];
    
    [_emailLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.userNameLab);
            make.bottom.equalTo(weakSelf.userIcon).offset(-5);
    }];
    
    [_arrowImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.offset(20);
            make.right.mas_offset(-15);
            make.centerY.mas_offset(0);
    }];
}

@end
